<?php

class Transport_DistrictController extends Base_Controller_Action
{

    public function nodeAction()
    {
        $district = new Model_District();
        try {
            $district->read($this->_getParam('pid'));
        }
        catch (Base_Model_Exception $e) {
            return $this->_helper->ErrorPage(404);
        }
        
        
    }

    public function manageAction()
    {
        if ($this->_getParam('pid')) {
            $district = new Model_District();
            try {
                $district->read($this->_getParam('pid'));
                $this->view->district = $district;
                
                //district path
                $this->view->path = $district->getPath();
            }
            catch (Base_Model_Exception $e) {
                return $this->_helper->ErrorPage(404);
            }
        }
        
        //question list
        $dbTable = new Table_District();
        $whereArray['`pid` = ?'] = (int) $this->_getParam('pid');
        $this->view->entries = $dbTable->view($whereArray, 'aid ASC');

    }
    
    public function createAction()
    {
        //create form
        $this->form = new Form_District_Create();
        
        try {
            $this->create('district');
        }
        catch (Base_Exception $e) {
            return $this->_helper->ErrorPage($e->getMessage());
        }
    }
    
    public function modifyAction()
    {
        //create form
        $this->form = new Form_District_Modify();
        
        try {
            $this->modify('district');
        }
        catch (Base_Exception $e) {
            return $this->_helper->ErrorPage($e->getMessage());
        }
    }
    
    public function deleteAction()
    {
        $this->form = new Form_District_Delete();
        
        //drop post
        try {
            $this->delete('district');
        }
        catch (Base_Exception $e) {
            return $this->_helper->ErrorPage($e->getMessage());
        }
    }
}